//获取应用实例
const app = getApp();

Page({
  data: {
    coupon: [],
    coupon_mony: 100,
    coupon_name: '无门槛带金券',
    coupon_date: '2019-09-09 至 2020-10-10',
    currentTap: 0,
    // 组件所需的参数
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '我的优惠券', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
  },
  onLoad() {
    let that = this;
    let url = app.globalData.URL + 'goods/coupon/user/list/0';
    let data = {};
    app.wxRequest('GET', url, data, (res) => {
      let coupon = res.rows
      that.setData({
        coupon: coupon
      })
      console.log(coupon)
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  order_status: function (e) {
    var current = e.currentTarget.dataset.current
    this.setData({
      currentTap: current
    })
    let that = this;
    let code = current;
    let url = app.globalData.URL + 'goods/coupon/user/list/' + code;
    let data = {};
    app.wxRequest('GET', url, data, (res) => {
      let coupon = res.rows
      that.setData({
        coupon: coupon
      })
      console.log(coupon)
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  // 选择优惠券
  addCououn(e) {
    console.log(e)
    let couponid = e.currentTarget.dataset.id;
    let couponPrice = e.currentTarget.dataset.price;
    let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
    let prevPage = pages[pages.length - 2];
    prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
      couponId: couponid,
      couponTitle:'已选择',
      couponPrice:couponPrice
    })
    prevPage.calculateTotal();
    wx.navigateBack({
      delta: 1  // 返回上一级页面。
    })
  }
})